package org.komarichin.struts2.actions.blogger;

import org.komarichin.beans.IComment;
import org.komarichin.beans.IPost;
import org.komarichin.beans.service.IBloggerService;
import org.komarichin.struts2.BaseAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;

/**
 * <p>
 * &nbsp;
 * </p>
 * User: Michael Komarichin
 * Date: Feb 13, 2010
 * Time: 9:23:08 PM
 */
public class BloggerAction extends BaseAction {
    private static final long serialVersionUID = -7791646616172511328L;

    private static final Logger log = LoggerFactory.getLogger(BloggerAction.class);

    @Autowired
    private IPost<String> post;
    @Autowired
    private IComment<String> comment;

    @Autowired
    private IBloggerService<String> bloggerService;

    public Collection<IPost> getBlogList() {
        return bloggerService.getPosts();
    }

    public String view() {
        post = bloggerService.getPost(post.getId());

        return SUCCESS;
    }

    public String save() {
        bloggerService.createPost(post);
        return SUCCESS;
    }

    public String addComment() {
        bloggerService.createComment(comment, post.getId());
        return SUCCESS;
    }

    public Collection<IComment> getComments() {
        return bloggerService.getComments(post.getId());
    }

    public IPost getPost() {
        return post;
    }

    public void setPost(IPost<String> post) {
        this.post = post;
    }

    public IComment getComment() {
        return comment;
    }

    public void setComment(IComment<String> comment) {
        this.comment = comment;
    }
}
